package com.leased.service.impl;

import com.leased.exception.DatabaseException;
import com.leased.interceptor.PageMybatisInterceptor;
import com.leased.mapper.UserVerifyMapper;
import com.leased.mapper.manual.ICustomizedUserVerifyMapper;
import com.leased.pojo.UserVerify;
import com.leased.request.cuser.CUserListRequest;
import com.leased.response.UserVerifyResponse;
import com.leased.service.UserAuthenticationService;
import com.leased.utils.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by shencx on 2017/8/2.
 */
@Service
public class UserAuthenticationServiceImpl implements UserAuthenticationService{

    Logger LOG = LoggerFactory.getLogger(UserLoginLimitServiceImpl.class);

    @Resource
    private ICustomizedUserVerifyMapper customizedUserVerifyMapper;

    @Resource
    private UserVerifyMapper userVerifyMapper;

    /**
     * 获取车主认证列表
     * @param cUserListRequest
     * @return
     * @throws DatabaseException
     */
    @Override
    public Page<UserVerifyResponse> fetchUserVerifyList(CUserListRequest cUserListRequest) throws DatabaseException {
        try {
            if (cUserListRequest == null){
                LOG.error("fetchUserVerifyList 信息为空",cUserListRequest);
                return null;
            }
            PageMybatisInterceptor.startPage(cUserListRequest.getPageNum(),cUserListRequest.getPageSize());
            customizedUserVerifyMapper.findUserVerifyList(cUserListRequest);
            Page<UserVerifyResponse> page = PageMybatisInterceptor.endPage();
            return page;
        } catch (Throwable e) {
            LOG.error("fetchUserVerifyList 发生异常",e,cUserListRequest);
            throw new DatabaseException(e.getMessage());
        }
    }

    /**
     * 更新审核状态
     * @param userVerify
     * @return
     * @throws DatabaseException
     */
    @Override
    public boolean updateUserVerifyInfo(UserVerify userVerify) throws DatabaseException {
        try {
            if (userVerify == null){
                LOG.error("updateUserVerifyInfo 信息为空",userVerify);
                return false;
            }
            Integer val = userVerifyMapper.updateByPrimaryKeySelective(userVerify);
            return val>0?true:false;
        } catch (Throwable e) {
            LOG.error("updateUserVerifyInfo 发生异常",e,userVerify);
            throw new DatabaseException(e.getMessage());
        }
    }
}
